package cn.com.greatwall.kafka.job;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import javax.annotation.PostConstruct;

import org.apache.commons.lang3.concurrent.BasicThreadFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import cn.com.greatwall.kafka.config.InitConfig;

/**
 * @Author herw
 * @Time 2021-04-15 13:30:13
 * @Version 1.0
 * @Description: TODO(用一句话描述该文件做什么)
 */
@Component
public class InitRunJob {
    @Autowired
    InitConfig initConfig;
    
    @Autowired
    CollectTopicJob collectTopicJob;

    private ScheduledExecutorService scheduledExecutorService = new ScheduledThreadPoolExecutor(7,
            new BasicThreadFactory.Builder().build());

    @PostConstruct
    public void init() {
        if(initConfig.isCollectTopicEnable()) {
            this.runCollectTopicData();
        }
    }

    private void runCollectTopicData() {
        scheduledExecutorService.scheduleWithFixedDelay(() -> collectTopicJob.collectionTopicData(), 1, initConfig.getCollectTopicPeriod(), TimeUnit.MINUTES);
    }
}
